import { _decorator, Component, Node, NodeEventType, Sprite, SpriteFrame } from 'cc';
import { colorType, effectType } from '../GameData';
import { resmgr } from './ResMgr';
import { SpriteFrameMgr } from './SpecialResMgr';
const { ccclass, property } = _decorator;

@ccclass('Card')

export class Card extends Component {
    color:colorType=null;
    private points:number=0;
    get point(){
        return this.points;
    }
    private SpriteF:Sprite=null;
    private effectType;
    istouch:boolean=false;   
    isUse:boolean=false;
    isMax:boolean=false;
    colorT: string[] = ["Spade","Heart","Diamond","Club"];
    pointT={2:"2",3:"3",4:"4",5:"5",6:"6",7:"7",8:"8",9:"9",10:"10",11:"J",12:"Q",13:"K",14:"A",};
    init(points:number,colorType:colorType,effectType?:effectType){
        this.points=points;
        this.color=colorType;
        this.effectType=effectType;
        //图片更换
        this.SpriteF=this.node.getComponent(Sprite);
        this.SpriteF.spriteFrame=resmgr.getMgr<SpriteFrameMgr>("SpriteFrameMgr").getRes<SpriteFrame>(this.colorT[this.color]+this.pointT[this.points]);
        //触碰事件
        this.node.on(NodeEventType.TOUCH_START,this.touch,this);
    }
    test(){
        console.log(this.color+" "+this.points);
    }
    touch(){
        //点击手牌抬起
        if(!this.istouch){
            //如果抬起牌数已经到达最大值则取消
            if (this.isMax) {
                return;
            }
            this.istouch=true;
            this.node.y+=50;
            return;
        }
        //点击抬起手牌落下
        this.istouch=false;
        this.node.y-=50;
    }

}


